const { NotFounError, success, fail } = require("../../utils/response");
const {
  config,
  client,
  singleFileUpload,
  singleFileUploads,
} = require("../../utils/aliyun");
// 查询文章列表处理函数
exports.uploadsfiles = async (req, res) => {
  try {
    // console.log(res.file);

    // 单文件上传
    singleFileUpload(
      req,
      res,
      function (err) {
        console.log(req.file.url);

        if (err) {
          return res.status(400).json({ msg: "上传失败!", err });
        }
        success(res, "上传成功!", { url: req.file.url });
      }
      // 多文件上传
      // singleFileUploads(req, res, function (err) {
      //     if (err) {
      //         return res.status(400).json({ msg: '上传失败!', err });
      //     }
      //     success(res, '上传成功!', { url: req.files.map(file => file.location) })
      // }
    );
  } catch (error) {
    fail(res, error);
  }
};
